package com.star.boxiaotong.once;

import com.alibaba.excel.EasyExcel;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class ImportDataInfo {
    public static void main(String[] args) {

        String column = "area";
        String fileName = "D:\\Ideaproject\\boxiaotong\\src\\main\\resources\\data.xlsx";
        // 这里 需要指定读用哪个class去读，然后读取第一个sheet 同步读取会自动finish
        List<DataInfo> dataInfoList =
                EasyExcel.read(fileName).head(DataInfo.class).sheet().doReadSync();
        System.out.println("总数 = " + dataInfoList.size());
        Map<String, List<DataInfo>> listMap =
                dataInfoList.stream()
                        .collect(Collectors.groupingBy(dataInfo -> dataInfo.getArea()));

        for (Map.Entry<String, List<DataInfo>> stringListEntry : listMap.entrySet()) {
            if (stringListEntry.getValue().size() > 0) {
                String importFile = "D:\\Ideaproject\\boxiaotong\\src\\main\\resources\\dataTest"+ stringListEntry.getKey()+".xlsx";
                EasyExcel.write(importFile, DataInfo.class).sheet("").doWrite(stringListEntry.getValue());

            }
        }
        System.out.println("不重复昵称数 = " + listMap.keySet().size());
    }

}
